android studioda emilatörde acamıyorum
11.03.2018 - 01:55
kodsal hatadan dolayı diye tahmin ediyorum ama hata yok kodlarımda yardımcı olabilecek var diskord,tw gibi kodları atıyorum düzeltme yaptığım yardımcı olursanız sevinirim
Değişiklik 1
package com.example.koko.myapplication;
import android.content.Intent;
import android.database.Cursor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.GridView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
GridView gridView;
ArrayList<Book> list;
Adapter adapter=null;
Button ekle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ekle=findViewById(R.id.btnEkle);
gridView=findViewById(R.id.gridView);
list=new ArrayList<>();
adapter=new Adapter(this,R.layout.items,list);
gridView.setAdapter(adapter);
Cursor cursor=Main2.sqLiteHelper.getData("SELECT*FROM BOOK");
list.clear();
while (cursor.moveToNext())
{
int id=cursor.getInt(0);
String name=cursor.getString(1);
String yazname=cursor.getString(2);
String details=cursor.getString(3);
byte[] image=cursor.getBlob(4);
list.add(new Book(id,name,yazname,details,image));
}
adapter.notifyDataSetChanged();
ekle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) { Intent ıntent=new Intent(MainActivity.this, Main2.class);
startActivity(ıntent);
}
});
}
}
değişiklik yaptığım 2
package com.example.koko.myapplication;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
/**
* Created by Koko on 11.03.2018.
*/
public class Adapter extends BaseAdapter
{
private Context context;
private int layout;
private ArrayList<Book> bookList;
public Adapter(Context context, int layout, ArrayList<Book> bookList) {
this.context = context;
this.layout = layout;
this.bookList = bookList;
}
@Override
public int getCount() {
return bookList.size();
}
@Override
public Object getItem(int position) {
return bookList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
private class ViewHolder
{
ImageView ımageView;
TextView txtname,txtyazname,details;
}
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
View row=view;
ViewHolder holder=new ViewHolder();
if (row==null)
{
LayoutInflater ınflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row=ınflater.inflate(layout,null);
holder.txtname=(TextView) row.findViewById(R.id.txtkadı);
holder.txtyazname=(TextView)row.findViewById(R.id.txtyadı);
holder.ımageView=(ImageView) row.findViewById(R.id.listimg);
row.setTag(holder);
}
else
{
holder=(ViewHolder) row.getTag();
}
Book book = bookList.get(position);
holder.txtname.setText(book.getName());
holder.txtyazname.setText(book.getYazname());
byte[] bookImage = book.getImage();
Bitmap bitmap = BitmapFactory.decodeByteArray(bookImage, 0, bookImage.length);
holder.ımageView.setImageBitmap(bitmap);
return row;
}
}
fark olan yada projeye bakmak istiyende olur ödevim yapamadım yardımcı olursanız sevinirim
8
Görüntülenme
0 Beğeni